package com.gitee.huxing.course.conc.conc02.atomic;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.conc.conc02
 * @ClassName: LongDemo
 * @Author: huxing
 * @DateTime: 2021-08-23 上午10:15
 */
public class LongDemo {

    public static void main(String[] args) {

        final AtomicLong atomicLong = new AtomicLong();

        final LongAdder longAdder = new LongAdder();

        for (int i=0; i< 100; i++){
            new Thread(() -> {
                for (int j= 0; j< 10000; j++){
                    atomicLong.getAndIncrement();
                    longAdder.increment();
                }
            }).start();
        }

        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("atomicLong= " + atomicLong.get());

        System.out.println("longAdder = " + longAdder.sum());
    }
}
